﻿using System;
using System.Text;
using BO.Infrastructure.Utils;
using BugManager;

namespace GUI.Controls.News
{
    public partial class ThreadGeneralList : System.Web.UI.UserControl
    {
        private const string LinkFormat = "<a href=\"{0}\" title=\"{2}\">{1}</a>";

        public string BoxTitle { get; set; }
        internal bool DataBind(Utilities.Entities.EmbedThreadGroup embedThreadGroup)
        {
            try
            {
                if (embedThreadGroup != null && embedThreadGroup.Threads != null && embedThreadGroup.Threads.Length > 0)
                {
                    var sb = new StringBuilder();
                    for (var i = 0; i < embedThreadGroup.Threads.Length; i++ )
                    {
                        var thread = embedThreadGroup.Threads[i];
                        sb.AppendFormat(LinkFormat, thread.OwnerInfo.Url, thread.OwnerInfo.Name,
                                        PresentationUtils.EnCode(thread.OwnerInfo.Name));
                        if (i < embedThreadGroup.Threads.Length - 1)
                            sb.Append("&nbsp;&nbsp;<span>▪</span>&nbsp;&nbsp;");
                    }
                    ltrData.Text = sb.ToString();
                    ltrBoxTitle.Text = BoxTitle;
                    return true;
                }
            }
            catch (Exception ex)
            {
                ErrorManager.Log(ex.ToString());
            }
            return false;
        }
    }
}